<?php

	/**
	 * @see Bike_Model_Mapper_Abstract
	 */
	require_once 'Bike/Model/Mapper/Abstract.php';
	
	/**
	 * @see Bike_Model_Mapper_Dependence
	 */
	require_once 'Bike/Model/Mapper/Dependence.php';
	
	class Bike_Model_Mapper_Language extends Bike_Model_Mapper_Abstract
	{
		const DB_TABLE_NAME = 'language';
		const DB_TABLE_PK_NAME = 'language_id';
		const DB_TABLE_ALIAS = 'l';
		const MODEL_CLASS = 'Bike_Model_Language';

		static public function getInstance()
	    {
	        return self::_getInstance(__CLASS__);
	    }

	    public function getDefaultValues()
	    {	    	return array(
	    		'status_id' => $this->getStatusIdActive(),
	    	);
	    }

	    protected function _getDependences()
	    {
	    	return array(
	    		$this->createDependence(array(
					'type' => Bike_Model_Mapper_Dependence::JOIN_LEFT,
					'name' => 'status',
					'mapperClass' => 'Bike_Model_Mapper_Status',
					'parentJoinFields' => array('status_id'),
				)),
	    	);
	    }
	    
	    public function getWindowTitleEdit(Bike_Model_Abstract $model)
	    {
	    	return $model->getTitleSystem();
	    }
	    
	    public function getTaskItemsSelect(Bike_Db_Mapper_Select $select)
	    {
	    	//$select->columns('language_id AS statusid');
	    	//@mail('d.mas@df-studio.net', __METHOD__, print_r($select->__toString(), true));
	    }
	    
	    public function getLanguageIdFieldParams($type = null)
	    {
	    	switch($type)
	    	{
	    		case self::PARAMS_COMMON: return array(
	    			'label' => $this->translate('Language ID'),
	    		);
	    		default: return array();
	    	}
	    }
	    
	    public function getCode2FieldParams($type = null)
	    {
	    	switch($type)
	    	{
	    		case self::PARAMS_COMMON: return array(
	    			'label' => $this->translate('Code (2)'),
	    		);
	    		case self::PARAMS_FORM_ELEMENT: return array(
	    			'description' => $this->translate("2 Letters ONLY! Starting from lowerrcase!<br />Example: 'en'"),
			    	'required' => true,
			    	'validators' => array(
				    	array('StringLength', False, array('min' => '2', 'max' => '2')),
				    	array('Regex', False, array('pattern' => '/^[a-z]{2}$/')),
			    	),
	    		);
	    		default: return array();
	    	}
	    }
	    
	    public function getCode3FieldParams($type = null)
	    {
	    	switch($type)
	    	{
	    		case self::PARAMS_COMMON: return array(
	    			'label' => $this->translate('Code (3)'),
	    		);
	    		case self::PARAMS_FORM_ELEMENT: return array(
	    			'description' => $this->translate("3 Letters ONLY! Starting from lowerrcase!<br />Example: 'eng'"),
			    	'required' => true,
			    	'validators' => array(
				    	array('StringLength', False, array('min' => '3', 'max' => '3')),
				    	array('Regex', False, array('pattern' => '/^[a-z]{3}$/')),
			    	),
	    		);
	    		default: return array();
	    	}
	    }
	    
	    public function getTitleFieldParams($type = null)
	    {
	    	switch($type)
	    	{
	    		case self::PARAMS_COMMON: return array(
	    			'label' => $this->translate('Title'),
	    		);
	    		case self::PARAMS_FORM_ELEMENT: return array(
	    			'description' => $this->translate("Title for users"),
				    'required' => true,
	    		);
	    		default: return array();
	    	}
	    }
	    
	    public function getTitleShortFieldParams($type = null)
	    {
	    	switch($type)
	    	{
	    		case self::PARAMS_COMMON: return array(
	    			'label' => $this->translate('Short title'),
	    		);
	    		case self::PARAMS_FORM_ELEMENT: return array(
	    			'description' => $this->translate("Short title for users"),
				    'required' => true,
	    		);
	    		default: return array();
	    	}
	    }
	    
	    public function getTitleSystemFieldParams($type = null)
	    {
	    	switch($type)
	    	{
	    		case self::PARAMS_COMMON: return array(
	    			'label' => $this->translate('System title'),
	    		);
	    		case self::PARAMS_FORM_ELEMENT: return array(
	    			'description' => $this->translate("Title for system and backend"),
	    			'required' => true,
	    		);
	    		default: return array();
	    	}
	    }
	    
	    public function getLocaleFieldParams($type = null)
	    {
	    	switch($type)
	    	{
	    		case self::PARAMS_COMMON: return array(
	    			'label' => $this->translate('Locale'),
	    		);
	    		case self::PARAMS_FORM_ELEMENT: return array(
		    		'description' => $this->translate("Locale for current language"),
		    		'required' => true,
	    		);
	    		default: return array();
	    	}
	    }
	    
	    public function getStatusIdFieldParams($type = null)
	    {
	    	switch($type)
	    	{
	    		case self::PARAMS_COMMON: return array(
	    			'label' => $this->translate('Status'),
	    		);
	    		case self::PARAMS_FORM_ELEMENT: return array(
	    			'type' => 'radio',
	    			'description' => $this->translate("Locale for current language"),
	    			'required' => false,
	    			'multiOptions' => Bike_Model_Mapper_Status::getInstance()->fetchAll()->getMultiOptions('status_id', 'title'),
	    		);
	    		case self::PARAMS_LIST_COLUMN: return array(
		    		'dataIndex' => $this->getLocalizedFieldName('status_title'),
	    		);
	    		default: return array();
	    	}
	    }
	}